<?php
/**
 * Created by PhpStorm.
 * User: 刘红波 <liuhb@cqjcdflzxsws.com>
 * Date: 2018/8/15
 * Time: 11:36
 */

namespace app\api\model;


use think\Model;

class BadWords extends Model
{
    protected $name = 'we_bad_words';

    public static function badWordsFilter($str){
        $data_list = array_column(collection(self::field('words')->select())->toArray(),'words');
//        $res = jieba(strtolower($str),1,50);
        if (empty($data_list)){
            return $str;
        }
        foreach ($data_list as $item){
//            ch2arr($item)
            $str = str_replace($item,replace($item),$str);
        }
        return $str;
    }
}